﻿<div class="demo-description" id="LoadChildNodesOnDemand">
    <h2>
        <DemoNavLink Link="TreeView#LoadChildNodesOnDemand" />TreeView - Load Child Nodes on Demand Mode
    </h2>
    <p>In this mode, the DevExpress <a class="helplink" target="_blank" href="https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxTreeView">TreeView</a> component loads a node’s children when the node is expanded for the first time. This mode allows you to improve the TreeView’s performance for tree structures with a large number of nodes.</p>
    <p>You can use the "<b>Load Child Nodes on Demand</b>" for bound and unbound TreeView nodes.</p>
    <p>The following API members are related to this mode:</p>
    <ul>
        <li><a class="helplink" target="_blank" href="https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxTreeView.LoadChildNodesOnDemand">LoadChildNodesOnDemand</a> - Specifies whether child nodes are loaded on demand.</li>
        <li><a class="helplink" target="_blank" href="https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxTreeView.HasChildrenExpression">HasChildrenExpression</a> - A lambda expression that specifies whether the data item has child items.</li>
    </ul>
</div>

<div class="card demo-card demo-card-shadow">
    <div class="card-body">
        <DxTreeView @ref="@treeView"
                    CssClass="mw-480"
                    Data="@DataSource"
                    LoadChildNodesOnDemand="true"
                    HasChildrenExpression="@(dataItem => ((DateTimeGroup)dataItem).HasSubGroups)"
                    ChildrenExpression="@(dataItem => ((DateTimeGroup)dataItem).GetSubGroups())"
                    TextExpression="@(dataItem => ((DateTimeGroup)dataItem).Title)">
        </DxTreeView>
    </div>
</div>

<CodeSnippet_TreeView_LoadChildNodesOnDemand></CodeSnippet_TreeView_LoadChildNodesOnDemand>

@code {
    DxTreeView treeView;

    IEnumerable<DateTimeGroup> DataSource = new List<DateTimeGroup>() {
        new DateTimeGroup(new DateTime(DateTime.Now.Year, 1, 1), DateTimeGroupType.Year)
    };

    protected override void OnAfterRender(bool firstRender)
    {
        if (firstRender) {
            var todayDate = DateTime.Now;
            treeView.SetNodeExpanded(n => n.Text == todayDate.Year.ToString(), true);
        }
        base.OnAfterRender(firstRender);
    }
}
